package com.tsystems.train.bean;

import java.io.Serializable;
import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

import com.tsystems.train.entity.TimeTableElement;

public class TTETableDataModel extends ListDataModel<TimeTableElement> implements
		SelectableDataModel<TimeTableElement>, Serializable {

	

	
	private static final long serialVersionUID = 3170725918988239610L;

	public TTETableDataModel() {
	}

	public TTETableDataModel(List<TimeTableElement> data) {
		super(data);
	}

	@SuppressWarnings("unchecked")
	public TimeTableElement getRowData(String rowKey) {
		List<TimeTableElement> timeTableElements = (List<TimeTableElement>) getWrappedData();

		for (TimeTableElement tte : timeTableElements) {
			String key = tte.getTrain().getNumber() + tte.getArrivalStation().getName()
					+ tte.getDepartureStation().getName()+tte.getDepartureTime().toString();
			if (key.equals(rowKey))
				return tte;
		}

		return null;
	}

	public Object getRowKey(TimeTableElement tte) {
		return tte.getTrain().getNumber() + tte.getArrivalStation().getName()
				+ tte.getDepartureStation().getName()+tte.getDepartureTime().toString();
	}
}
